<template>
  <div class="detail">
    <c-section title="设计任务处理">
      <c-list :column="3" label-width="140px">
        <c-list-item label="任务类型" dict-type-code="TASK_TYPE" :value="detail.taskType" />
        <c-list-item label="数据来源" dict-type-code="DATA_SOURCE" :value="detail.dataSource" />
        <c-list-item label="任务来源单据" clickable :value="detail.sourceCode" @click.native="toSource(detail.sourceCode)" />
        <c-list-item label="任务分配时间" :format-time="false" :value="detail.distributeTime" />
        <c-list-item label="门店建设项目号" :value="detail.constCode" />
        <c-list-item label="设计范围" dict-type-code="DECORATION_RANGE" :value="detail.designRange || detail.decorationRange" />
        <c-list-item label="所属门店编码" :value="detail.shopCode" />
        <c-list-item label="所属门店" :value="detail.shopName" />
        <c-list-item label="所属客户编码" :value="detail.clientCode" />
        <c-list-item label="所属客户" :value="detail.clientName" />
        <c-list-item label="所属办事处" :value="detail.officeName" />
        <c-list-item label="门店建设范围" dict-type-code="DECORATION_RANGE" :value="detail.decorationRange" />
        <c-list-item label="装修形式" dict-type-code="DECORATION_FORM" :value="detail.decorationType || detail.decorationForm" />
        <c-list-item label="是否需要复尺" dict-type-code="BOOLEANS" :value="detail.isNeedResurvey" />
        <c-list-item label="是否完成复尺" dict-type-code="BOOLEANS" :value="detail.isEndResurvey" />
        <c-list-item label="不复尺设计摆场" dict-type-code="UNRESURVEY_STATE" :value="detail.unresurveyDesignSetup" />
        <c-list-item label="不复尺设计施工" dict-type-code="UNRESURVEY_STATE" :value="detail.unresurveyDesignConst" />
      </c-list>
      <!-- 十月优化START -->
      <Area :detail="detail" :pic-detail="picDetail" :design-detail="designDetail" />
      <!-- 十月优化END -->
      <c-list :column="3" label-width="140px">
        <c-list-item label="设计单位" :value="detail.designUnitName" />
        <c-list-item label="申请说明" :value="detail.taskDesc || detail.applyDesc" :span="3" />
        <c-list-item label="门头预计设计完成时间" :value="detail.dheadExpectCompleteTime" />
        <c-list-item label="卖场预计设计完成时间" :value="detail.marketExpectCompleteTime" />
        <c-list-item label="是否KA卖场" dict-type-code="BOOLEANS" :value="detail.isKaMarket" />
        <c-list-item label="图纸紧急程度" dict-type-code="PIC_URGENT_LEVEL" :value="detail.picUrgentLevel" />
        <c-list-item label="店面等级" dict-type-code="SHOP_LEVEL_CODE" :value="detail.shopLevelCode" />
        <c-list-item label="重点市场" dict-type-code="BOOLEANS" :value="detail.isFocusMarket" />
        <c-list-item label="是否重复设计" dict-type-code="BOOLEANS" :value="detail.haveRedesign===undefined||detail.haveRedesign===''?detail.isRedesign:detail.haveRedesign" />
        <c-list-item label="重复设计原因" dict-type-code="REDESIGN_REASON" :value="detail.redesignReason" />
        <c-list-item label="是否需要门头效果图" dict-type-code="BOOLEANS" :value="designDetail.isNeedRendering" />
        <c-list-item label="任务处理方式" dict-type-code="TASK_HANDEL_WAY" :value="detail.taskHandelWay" />
        <c-list-item label="任务分配结果" dict-type-code="DISTRIBUTE_RESULT" :value="detail.distributeResult" />
        <c-list-item label="任务终止原因" :value="detail.endReason" :span="3" />
      </c-list>
    </c-section>
    <c-section title="图纸变更结果（仅显示本次新增/变更的图纸）">
      <c-table-box index hide-func :setting="false" :table-height="400" :data="resultTableData" :table-config="tableConfig" />
    </c-section>
    <c-section title="任务处理结果审核">
      <c-list>
        <c-list-item label="审核结果" one="同意" zero="不同意" :value="detail.reviewResult" />
        <c-list-item label="审批意见" :value="detail.reviewAdvice" />
      </c-list>
    </c-section>
    <div class="btn-container">
      <c-button type="primary" @click="goBack">返回</c-button>
    </div>
  </div>
</template>
<script>
import { getShopDesignTaskInfo, shopConstructPage, getShopDesignTaskWholeInfo, basicsInfo, getPicinfo, getShopDesignInfo } from '@/api/shopDesignTask'
import { getPicturePage } from './getPath'
import { getPath } from './getPath'
import { concatObj } from '@/utils'
import Area from './components/Area'
export default {
  name: 'ShopDesignTaskDetail',
  components: {
    Area
  },
  data() {
    return {
      allConfigArea: [],
      designDetail: {},
      taskDetail: {},
      picDetail: {},
      shopDetail: {},
      wholeInfo: {},
      basicInfoData: {},
      resultTableData: [],
      tableConfig: {
        setting: [
          {
            prop: 'picTaskCode',
            label: '图纸任务编码',
            minWidth: 140
          },
          {
            prop: 'picTaskName',
            label: '图纸名称',
            minWidth: 140
          },
          {
            prop: 'picType',
            label: '图纸类型',
            minWidth: 100,
            propEnum: {
              domainCode: 'marketing',
              appCode: 'slm',
              dictTypeCode: 'PIC_TYPE'
            }
          },
          {
            prop: 'designRange',
            label: '设计范围',
            minWidth: 120,
            render: (h, row) => h('c-dict-range-view', {
              props: {
                dictTypeCode: 'DECORATION_RANGE',
                value: row.designRange
              }
            })
          },
          {
            prop: 'decorationType',
            label: '装修形式',
            minWidth: 100,
            render: (h, row) => h('c-dict-range-view', {
              props: {
                dictTypeCode: 'DECORATION_FORM',
                value: row.decorationType
              }
            })
          },
          {
            prop: 'designSpace',
            label: '设计区域',
            minWidth: 140,
            render: (h, row) => {
              return h('c-design-area', { props: { value: row.designSpace }})
            }
          },
          {
            prop: 'designBizType',
            label: '设计业务类型',
            minWidth: 140,
            render: (h, row) => h('c-dict-range-view', {
              props: {
                dictTypeCode: 'BIZ_TYPE',
                value: row.designBizType
              }
            })
          },
          {
            prop: 'picTotalArea',
            label: '图纸总面积',
            minWidth: 100
          },
          // 图纸总面积字段后增加字段-成品总面积、新业务总面积、
          // 是否含成融定、成融定面积、是否重复设计、来源图纸
          {
            prop: 'softwareSumArea',
            label: '软体区总面积',
            minWidth: '120'
          },
          {
            prop: 'suiteSumArea',
            label: '套房区总面积',
            minWidth: '120'
          },
          {
            prop: 'newBusinessAreaSummary',
            label: '新业务总面积',
            minWidth: '120'
          },
          {
            prop: 'haveEAndC',
            label: '是否含成融定',
            width: '100',
            propEnum: {
              domainCode: 'marketing',
              appCode: 'slm',
              dictTypeCode: 'BOOLEANS'
            }
          },
          {
            prop: 'eandCArea',
            label: '成融定面积',
            width: '100'
          },
          {
            prop: 'isRedesign',
            label: '是否重复设计',
            width: '100',
            propEnum: {
              domainCode: 'marketing',
              appCode: 'slm',
              dictTypeCode: 'BOOLEANS'
            }
          },
          {
            prop: 'sourcePicName',
            label: '来源图纸',
            width: '180'
          },
          {
            prop: 'designerName',
            label: '设计师',
            minWidth: 100
          },
          {
            prop: 'taskHandleType',
            label: '任务处理结果',
            minWidth: 100,
            render: (h, row) => {
              // 处理任务方式 0修改,1暂停，2恢复,3作废
              return h('span', this.taskHandleTypeName(row.taskHandleType))
            }
          }
        ]
      }
    }
  },
  computed: {
    detail() {
      return concatObj(this.picDetail, this.taskDetail, this.wholeInfo, this.designDetail, this.shopDetail)
      // return { ...this.designDetail, ...this.taskDetail }
    }
  },
  created() {
    this.getDetail()
  },
  methods: {
    async getDetail() {
      const { id } = this.$route.query
      await getShopDesignTaskInfo(id).then(res => {
        // this.resultTableData = [...(res.data.shopDesignPictureDTOList || []), ...(res.data.shopDesignPictureChangeList || [])]
        this.taskDetail = res.data
        shopConstructPage(res.data.constCode).then(res => {
          this.shopDetail = res.data.records.length > 0 ? res.data.records[0] : {}
        })
        if (this.taskDetail.taskType === 'DRAWING_TRIGGER') {
          getPicturePage(this.taskDetail.sourceCode).then(data => {
            this.picDetail = data
          })
        }
        // 获取设计信息
        getShopDesignInfo(res.data.constCode).then(res => {
          this.designDetail = res.data
        })
      })

      if (this.taskDetail.taskType === 'DESIGN_CHANGE') {
        await basicsInfo(this.$route.query.id).then(res => {
          this.wholeInfo = res.data
        })
      } else {
        // 获取全部详情  设计变更报错
        await getShopDesignTaskWholeInfo(this.$route.query.id).then(res => {
          this.wholeInfo = res.data
        })
      }
      getPicinfo(id).then(res => {
        this.resultTableData = res.data
      })
    },
    taskHandleTypeName(v) {
      // 处理任务方式 0修改,1暂停，2恢复,3作废
      const t = { 0: '修改', 1: '暂停', 2: '恢复', 3: '作废', 4: '新增' }
      v = (v === undefined || v === null) ? '' : v.toString()
      const names = []
      this.$split(v).forEach(e => {
        if (t[e]) {
          names.push(t[e])
        }
      })
      return names.join(',')
    },
    goBack() {
      this.$store.dispatch('views/goFirst')
    },
    async toSource(v) {
      const { path, query } = await getPath(this.detail.taskType, v)
      if (!path) return
      query ? query.time = new Date().getTime() : ''
      this.$store.dispatch('views/goPage', { path, query })
    }
  }
}
</script>
<style lang="scss" scoped>
.detail{

}
</style>
